package com.melesta.payment.inapp3;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
import android.text.TextUtils;
import android.util.Log;
import com.android.vending.billing.IInAppBillingService;
import com.android.vending.billing.IInAppBillingService.Stub;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.json.JSONException;

public class IabHelper
{
  public static final int BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE = 3;
  public static final int BILLING_RESPONSE_RESULT_DEVELOPER_ERROR = 5;
  public static final int BILLING_RESPONSE_RESULT_ERROR = 6;
  public static final int BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED = 7;
  public static final int BILLING_RESPONSE_RESULT_ITEM_NOT_OWNED = 8;
  public static final int BILLING_RESPONSE_RESULT_ITEM_UNAVAILABLE = 4;
  public static final int BILLING_RESPONSE_RESULT_OK = 0;
  public static final int BILLING_RESPONSE_RESULT_USER_CANCELED = 1;
  public static final String GET_SKU_DETAILS_ITEM_LIST = "ITEM_ID_LIST";
  public static final String GET_SKU_DETAILS_ITEM_TYPE_LIST = "ITEM_TYPE_LIST";
  public static final int IABHELPER_BAD_RESPONSE = -1002;
  public static final int IABHELPER_ERROR_BASE = -1000;
  public static final int IABHELPER_INVALID_CONSUMPTION = -1010;
  public static final int IABHELPER_MISSING_TOKEN = -1007;
  public static final int IABHELPER_REMOTE_EXCEPTION = -1001;
  public static final int IABHELPER_SEND_INTENT_FAILED = -1004;
  public static final int IABHELPER_SUBSCRIPTIONS_NOT_AVAILABLE = -1009;
  public static final int IABHELPER_UNKNOWN_ERROR = -1008;
  public static final int IABHELPER_UNKNOWN_PURCHASE_RESPONSE = -1006;
  public static final int IABHELPER_USER_CANCELLED = -1005;
  public static final int IABHELPER_VERIFICATION_FAILED = -1003;
  public static final String INAPP_CONTINUATION_TOKEN = "INAPP_CONTINUATION_TOKEN";
  public static final String ITEM_TYPE_INAPP = "inapp";
  public static final String ITEM_TYPE_SUBS = "subs";
  public static final String RESPONSE_BUY_INTENT = "BUY_INTENT";
  public static final String RESPONSE_CODE = "RESPONSE_CODE";
  public static final String RESPONSE_GET_SKU_DETAILS_LIST = "DETAILS_LIST";
  public static final String RESPONSE_INAPP_ITEM_LIST = "INAPP_PURCHASE_ITEM_LIST";
  public static final String RESPONSE_INAPP_PURCHASE_DATA = "INAPP_PURCHASE_DATA";
  public static final String RESPONSE_INAPP_PURCHASE_DATA_LIST = "INAPP_PURCHASE_DATA_LIST";
  public static final String RESPONSE_INAPP_SIGNATURE = "INAPP_DATA_SIGNATURE";
  public static final String RESPONSE_INAPP_SIGNATURE_LIST = "INAPP_DATA_SIGNATURE_LIST";
  boolean mAsyncInProgress = false;
  String mAsyncOperation = "";
  Context mContext;
  boolean mDebugLog = false;
  String mDebugTag = "IabHelper";
  OnIabPurchaseFinishedListener mPurchaseListener;
  String mPurchasingItemType;
  int mRequestCode;
  IInAppBillingService mService;
  ServiceConnection mServiceConn;
  boolean mSetupDone = false;
  String mSignatureBase64 = null;
  boolean mSubscriptionsSupported = false;

  public IabHelper(Context paramContext, String paramString)
  {
    this.mContext = paramContext.getApplicationContext();
    this.mSignatureBase64 = paramString;
    logDebug("IAB helper created.");
  }

  public static String getResponseDesc(int paramInt)
  {
    String[] arrayOfString1 = "0:OK/1:User Canceled/2:Unknown/3:Billing Unavailable/4:Item unavailable/5:Developer Error/6:Error/7:Item Already Owned/8:Item not owned".split("/");
    String[] arrayOfString2 = "0:OK/-1001:Remote exception during initialization/-1002:Bad response received/-1003:Purchase signature verification failed/-1004:Send intent failed/-1005:User cancelled/-1006:Unknown purchase response/-1007:Missing token/-1008:Unknown error/-1009:Subscriptions not available/-1010:Invalid consumption attempt".split("/");
    if (paramInt <= -1000)
    {
      int i = -1000 - paramInt;
      if ((i >= 0) && (i < arrayOfString2.length))
        return arrayOfString2[i];
      return String.valueOf(paramInt) + ":Unknown IAB Helper Error";
    }
    if ((paramInt < 0) || (paramInt >= arrayOfString1.length))
      return String.valueOf(paramInt) + ":Unknown";
    return arrayOfString1[paramInt];
  }

  void checkSetupDone(String paramString)
  {
    if (!this.mSetupDone)
    {
      logError("Illegal state for operation (" + paramString + "): IAB helper is not set up.");
      throw new IllegalStateException("IAB helper is not set up. Can't perform operation: " + paramString);
    }
  }

  void consume(Purchase paramPurchase)
    throws IabException
  {
    checkSetupDone("consume");
    if (!paramPurchase.mItemType.equals("inapp"))
      throw new IabException(-1010, "Items of type '" + paramPurchase.mItemType + "' can't be consumed.");
    String str1;
    String str2;
    try
    {
      str1 = paramPurchase.getToken();
      str2 = paramPurchase.getSku();
      if ((str1 == null) || (str1.equals("")))
      {
        logError("Can't consume " + str2 + ". No token.");
        throw new IabException(-1007, "PurchaseInfo is missing token for sku: " + str2 + " " + paramPurchase);
      }
    }
    catch (RemoteException localRemoteException)
    {
      throw new IabException(-1001, "Remote exception while consuming. PurchaseInfo: " + paramPurchase, localRemoteException);
    }
    logDebug("Consuming sku: " + str2 + ", token: " + str1);
    int i = this.mService.consumePurchase(3, this.mContext.getPackageName(), str1);
    if (i == 0)
    {
      logDebug("Successfully consumed sku: " + str2);
      return;
    }
    logDebug("Error consuming consuming sku " + str2 + ". " + getResponseDesc(i));
    throw new IabException(i, "Error consuming sku " + str2);
  }

  public void consumeAsync(Purchase paramPurchase, OnConsumeFinishedListener paramOnConsumeFinishedListener)
  {
    checkSetupDone("consume");
    ArrayList localArrayList = new ArrayList();
    localArrayList.add(paramPurchase);
    consumeAsyncInternal(localArrayList, paramOnConsumeFinishedListener, null);
  }

  public void consumeAsync(List<Purchase> paramList, OnConsumeMultiFinishedListener paramOnConsumeMultiFinishedListener)
  {
    checkSetupDone("consume");
    consumeAsyncInternal(paramList, null, paramOnConsumeMultiFinishedListener);
  }

  void consumeAsyncInternal(final List<Purchase> paramList, final OnConsumeFinishedListener paramOnConsumeFinishedListener, final OnConsumeMultiFinishedListener paramOnConsumeMultiFinishedListener)
  {
    final Handler localHandler = new Handler();
    flagStartAsync("consume");
    new Thread(new Runnable()
    {
      public void run()
      {
        final ArrayList localArrayList = new ArrayList();
        Iterator localIterator = paramList.iterator();
        while (localIterator.hasNext())
        {
          Purchase localPurchase = (Purchase)localIterator.next();
          try
          {
            IabHelper.this.consume(localPurchase);
            localArrayList.add(new IabResult(0, "Successful consume of sku " + localPurchase.getSku()));
          }
          catch (IabException localIabException)
          {
            localArrayList.add(localIabException.getResult());
          }
        }
        IabHelper.this.flagEndAsync();
        if (paramOnConsumeFinishedListener != null)
          localHandler.post(new Runnable()
          {
            public void run()
            {
              IabHelper.3.this.val$singleListener.onConsumeFinished((Purchase)IabHelper.3.this.val$purchases.get(0), (IabResult)localArrayList.get(0));
            }
          });
        if (paramOnConsumeMultiFinishedListener != null)
          localHandler.post(new Runnable()
          {
            public void run()
            {
              IabHelper.3.this.val$multiListener.onConsumeMultiFinished(IabHelper.3.this.val$purchases, localArrayList);
            }
          });
      }
    }).start();
  }

  public void dispose()
  {
    logDebug("Disposing.");
    this.mSetupDone = false;
    if (this.mServiceConn != null)
    {
      logDebug("Unbinding from service.");
      if (this.mContext != null)
        this.mContext.unbindService(this.mServiceConn);
      this.mServiceConn = null;
      this.mService = null;
      this.mPurchaseListener = null;
    }
  }

  public void enableDebugLogging(boolean paramBoolean)
  {
    this.mDebugLog = paramBoolean;
  }

  public void enableDebugLogging(boolean paramBoolean, String paramString)
  {
    this.mDebugLog = paramBoolean;
    this.mDebugTag = paramString;
  }

  void flagEndAsync()
  {
    logDebug("Ending async operation: " + this.mAsyncOperation);
    this.mAsyncOperation = "";
    this.mAsyncInProgress = false;
  }

  void flagStartAsync(String paramString)
  {
    if (this.mAsyncInProgress)
      throw new IllegalStateException("Can't start async operation (" + paramString + ") because another async operation(" + this.mAsyncOperation + ") is in progress.");
    this.mAsyncOperation = paramString;
    this.mAsyncInProgress = true;
    logDebug("Starting async operation: " + paramString);
  }

  int getResponseCodeFromBundle(Bundle paramBundle)
  {
    Object localObject = paramBundle.get("RESPONSE_CODE");
    if (localObject == null)
    {
      logDebug("Bundle with null response code, assuming OK (known issue)");
      return 0;
    }
    if ((localObject instanceof Integer))
      return ((Integer)localObject).intValue();
    if ((localObject instanceof Long))
      return (int)((Long)localObject).longValue();
    logError("Unexpected type for bundle response code.");
    logError(localObject.getClass().getName());
    throw new RuntimeException("Unexpected type for bundle response code: " + localObject.getClass().getName());
  }

  int getResponseCodeFromIntent(Intent paramIntent)
  {
    Object localObject = paramIntent.getExtras().get("RESPONSE_CODE");
    if (localObject == null)
    {
      logError("Intent with no response code, assuming OK (known issue)");
      return 0;
    }
    if ((localObject instanceof Integer))
      return ((Integer)localObject).intValue();
    if ((localObject instanceof Long))
      return (int)((Long)localObject).longValue();
    logError("Unexpected type for intent response code.");
    logError(localObject.getClass().getName());
    throw new RuntimeException("Unexpected type for intent response code: " + localObject.getClass().getName());
  }

  // ERROR //
  public boolean handleActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
  {
    // Byte code:
    //   0: iload_1
    //   1: aload_0
    //   2: getfield 373	com/melesta/payment/inapp3/IabHelper:mRequestCode	I
    //   5: if_icmpeq +5 -> 10
    //   8: iconst_0
    //   9: ireturn
    //   10: aload_0
    //   11: ldc_w 374
    //   14: invokevirtual 191	com/melesta/payment/inapp3/IabHelper:checkSetupDone	(Ljava/lang/String;)V
    //   17: aload_0
    //   18: invokevirtual 376	com/melesta/payment/inapp3/IabHelper:flagEndAsync	()V
    //   21: aload_3
    //   22: ifnonnull +46 -> 68
    //   25: aload_0
    //   26: ldc_w 378
    //   29: invokevirtual 176	com/melesta/payment/inapp3/IabHelper:logError	(Ljava/lang/String;)V
    //   32: new 380	com/melesta/payment/inapp3/IabResult
    //   35: dup
    //   36: sipush -1002
    //   39: ldc_w 382
    //   42: invokespecial 383	com/melesta/payment/inapp3/IabResult:<init>	(ILjava/lang/String;)V
    //   45: astore 16
    //   47: aload_0
    //   48: getfield 301	com/melesta/payment/inapp3/IabHelper:mPurchaseListener	Lcom/melesta/payment/inapp3/IabHelper$OnIabPurchaseFinishedListener;
    //   51: ifnull +15 -> 66
    //   54: aload_0
    //   55: getfield 301	com/melesta/payment/inapp3/IabHelper:mPurchaseListener	Lcom/melesta/payment/inapp3/IabHelper$OnIabPurchaseFinishedListener;
    //   58: aload 16
    //   60: aconst_null
    //   61: invokeinterface 389 3 0
    //   66: iconst_1
    //   67: ireturn
    //   68: aload_0
    //   69: aload_3
    //   70: invokevirtual 391	com/melesta/payment/inapp3/IabHelper:getResponseCodeFromIntent	(Landroid/content/Intent;)I
    //   73: istore 4
    //   75: aload_3
    //   76: ldc 72
    //   78: invokevirtual 395	android/content/Intent:getStringExtra	(Ljava/lang/String;)Ljava/lang/String;
    //   81: astore 5
    //   83: aload_3
    //   84: ldc 78
    //   86: invokevirtual 395	android/content/Intent:getStringExtra	(Ljava/lang/String;)Ljava/lang/String;
    //   89: astore 6
    //   91: iload_2
    //   92: iconst_m1
    //   93: if_icmpne +409 -> 502
    //   96: iload 4
    //   98: ifne +404 -> 502
    //   101: aload_0
    //   102: ldc_w 397
    //   105: invokevirtual 136	com/melesta/payment/inapp3/IabHelper:logDebug	(Ljava/lang/String;)V
    //   108: aload_0
    //   109: new 152	java/lang/StringBuilder
    //   112: dup
    //   113: invokespecial 153	java/lang/StringBuilder:<init>	()V
    //   116: ldc_w 399
    //   119: invokevirtual 160	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   122: aload 5
    //   124: invokevirtual 160	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   127: invokevirtual 166	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   130: invokevirtual 136	com/melesta/payment/inapp3/IabHelper:logDebug	(Ljava/lang/String;)V
    //   133: aload_0
    //   134: new 152	java/lang/StringBuilder
    //   137: dup
    //   138: invokespecial 153	java/lang/StringBuilder:<init>	()V
    //   141: ldc_w 401
    //   144: invokevirtual 160	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   147: aload 6
    //   149: invokevirtual 160	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   152: invokevirtual 166	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   155: invokevirtual 136	com/melesta/payment/inapp3/IabHelper:logDebug	(Ljava/lang/String;)V
    //   158: aload_0
    //   159: new 152	java/lang/StringBuilder
    //   162: dup
    //   163: invokespecial 153	java/lang/StringBuilder:<init>	()V
    //   166: ldc_w 403
    //   169: invokevirtual 160	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   172: aload_3
    //   173: invokevirtual 361	android/content/Intent:getExtras	()Landroid/os/Bundle;
    //   176: invokevirtual 224	java/lang/StringBuilder:append	(Ljava/lang/Object;)Ljava/lang/StringBuilder;
    //   179: invokevirtual 166	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   182: invokevirtual 136	com/melesta/payment/inapp3/IabHelper:logDebug	(Ljava/lang/String;)V
    //   185: aload_0
    //   186: new 152	java/lang/StringBuilder
    //   189: dup
    //   190: invokespecial 153	java/lang/StringBuilder:<init>	()V
    //   193: ldc_w 405
    //   196: invokevirtual 160	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   199: aload_0
    //   200: getfield 407	com/melesta/payment/inapp3/IabHelper:mPurchasingItemType	Ljava/lang/String;
    //   203: invokevirtual 160	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   206: invokevirtual 166	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   209: invokevirtual 136	com/melesta/payment/inapp3/IabHelper:logDebug	(Ljava/lang/String;)V
    //   212: aload 5
    //   214: ifnull +8 -> 222
    //   217: aload 6
    //   219: ifnonnull +76 -> 295
    //   222: aload_0
    //   223: ldc_w 409
    //   226: invokevirtual 176	com/melesta/payment/inapp3/IabHelper:logError	(Ljava/lang/String;)V
    //   229: aload_0
    //   230: new 152	java/lang/StringBuilder
    //   233: dup
    //   234: invokespecial 153	java/lang/StringBuilder:<init>	()V
    //   237: ldc_w 403
    //   240: invokevirtual 160	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   243: aload_3
    //   244: invokevirtual 361	android/content/Intent:getExtras	()Landroid/os/Bundle;
    //   247: invokevirtual 410	android/os/Bundle:toString	()Ljava/lang/String;
    //   250: invokevirtual 160	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   253: invokevirtual 166	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   256: invokevirtual 136	com/melesta/payment/inapp3/IabHelper:logDebug	(Ljava/lang/String;)V
    //   259: new 380	com/melesta/payment/inapp3/IabResult
    //   262: dup
    //   263: sipush -1008
    //   266: ldc_w 412
    //   269: invokespecial 383	com/melesta/payment/inapp3/IabResult:<init>	(ILjava/lang/String;)V
    //   272: astore 10
    //   274: aload_0
    //   275: getfield 301	com/melesta/payment/inapp3/IabHelper:mPurchaseListener	Lcom/melesta/payment/inapp3/IabHelper$OnIabPurchaseFinishedListener;
    //   278: ifnull +15 -> 293
    //   281: aload_0
    //   282: getfield 301	com/melesta/payment/inapp3/IabHelper:mPurchaseListener	Lcom/melesta/payment/inapp3/IabHelper$OnIabPurchaseFinishedListener;
    //   285: aload 10
    //   287: aconst_null
    //   288: invokeinterface 389 3 0
    //   293: iconst_1
    //   294: ireturn
    //   295: new 193	com/melesta/payment/inapp3/Purchase
    //   298: dup
    //   299: aload_0
    //   300: getfield 407	com/melesta/payment/inapp3/IabHelper:mPurchasingItemType	Ljava/lang/String;
    //   303: aload 5
    //   305: aload 6
    //   307: invokespecial 415	com/melesta/payment/inapp3/Purchase:<init>	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
    //   310: astore 11
    //   312: aload 11
    //   314: invokevirtual 213	com/melesta/payment/inapp3/Purchase:getSku	()Ljava/lang/String;
    //   317: astore 14
    //   319: aload_0
    //   320: getfield 122	com/melesta/payment/inapp3/IabHelper:mSignatureBase64	Ljava/lang/String;
    //   323: aload 5
    //   325: aload 6
    //   327: invokestatic 421	com/melesta/payment/inapp3/Security:verifyPurchase	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z
    //   330: ifne +84 -> 414
    //   333: aload_0
    //   334: new 152	java/lang/StringBuilder
    //   337: dup
    //   338: invokespecial 153	java/lang/StringBuilder:<init>	()V
    //   341: ldc_w 423
    //   344: invokevirtual 160	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   347: aload 14
    //   349: invokevirtual 160	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   352: invokevirtual 166	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   355: invokevirtual 176	com/melesta/payment/inapp3/IabHelper:logError	(Ljava/lang/String;)V
    //   358: new 380	com/melesta/payment/inapp3/IabResult
    //   361: dup
    //   362: sipush -1003
    //   365: new 152	java/lang/StringBuilder
    //   368: dup
    //   369: invokespecial 153	java/lang/StringBuilder:<init>	()V
    //   372: ldc_w 425
    //   375: invokevirtual 160	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   378: aload 14
    //   380: invokevirtual 160	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   383: invokevirtual 166	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   386: invokespecial 383	com/melesta/payment/inapp3/IabResult:<init>	(ILjava/lang/String;)V
    //   389: astore 15
    //   391: aload_0
    //   392: getfield 301	com/melesta/payment/inapp3/IabHelper:mPurchaseListener	Lcom/melesta/payment/inapp3/IabHelper$OnIabPurchaseFinishedListener;
    //   395: ifnull +328 -> 723
    //   398: aload_0
    //   399: getfield 301	com/melesta/payment/inapp3/IabHelper:mPurchaseListener	Lcom/melesta/payment/inapp3/IabHelper$OnIabPurchaseFinishedListener;
    //   402: aload 15
    //   404: aload 11
    //   406: invokeinterface 389 3 0
    //   411: goto +312 -> 723
    //   414: aload_0
    //   415: ldc_w 427
    //   418: invokevirtual 136	com/melesta/payment/inapp3/IabHelper:logDebug	(Ljava/lang/String;)V
    //   421: aload_0
    //   422: getfield 301	com/melesta/payment/inapp3/IabHelper:mPurchaseListener	Lcom/melesta/payment/inapp3/IabHelper$OnIabPurchaseFinishedListener;
    //   425: ifnull +25 -> 450
    //   428: aload_0
    //   429: getfield 301	com/melesta/payment/inapp3/IabHelper:mPurchaseListener	Lcom/melesta/payment/inapp3/IabHelper$OnIabPurchaseFinishedListener;
    //   432: new 380	com/melesta/payment/inapp3/IabResult
    //   435: dup
    //   436: iconst_0
    //   437: ldc_w 429
    //   440: invokespecial 383	com/melesta/payment/inapp3/IabResult:<init>	(ILjava/lang/String;)V
    //   443: aload 11
    //   445: invokeinterface 389 3 0
    //   450: iconst_1
    //   451: ireturn
    //   452: astore 12
    //   454: aload_0
    //   455: ldc_w 431
    //   458: invokevirtual 176	com/melesta/payment/inapp3/IabHelper:logError	(Ljava/lang/String;)V
    //   461: aload 12
    //   463: invokevirtual 434	org/json/JSONException:printStackTrace	()V
    //   466: new 380	com/melesta/payment/inapp3/IabResult
    //   469: dup
    //   470: sipush -1002
    //   473: ldc_w 431
    //   476: invokespecial 383	com/melesta/payment/inapp3/IabResult:<init>	(ILjava/lang/String;)V
    //   479: astore 13
    //   481: aload_0
    //   482: getfield 301	com/melesta/payment/inapp3/IabHelper:mPurchaseListener	Lcom/melesta/payment/inapp3/IabHelper$OnIabPurchaseFinishedListener;
    //   485: ifnull +15 -> 500
    //   488: aload_0
    //   489: getfield 301	com/melesta/payment/inapp3/IabHelper:mPurchaseListener	Lcom/melesta/payment/inapp3/IabHelper$OnIabPurchaseFinishedListener;
    //   492: aload 13
    //   494: aconst_null
    //   495: invokeinterface 389 3 0
    //   500: iconst_1
    //   501: ireturn
    //   502: iload_2
    //   503: iconst_m1
    //   504: if_icmpne +67 -> 571
    //   507: aload_0
    //   508: new 152	java/lang/StringBuilder
    //   511: dup
    //   512: invokespecial 153	java/lang/StringBuilder:<init>	()V
    //   515: ldc_w 436
    //   518: invokevirtual 160	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   521: iload 4
    //   523: invokestatic 252	com/melesta/payment/inapp3/IabHelper:getResponseDesc	(I)Ljava/lang/String;
    //   526: invokevirtual 160	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   529: invokevirtual 166	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   532: invokevirtual 136	com/melesta/payment/inapp3/IabHelper:logDebug	(Ljava/lang/String;)V
    //   535: aload_0
    //   536: getfield 301	com/melesta/payment/inapp3/IabHelper:mPurchaseListener	Lcom/melesta/payment/inapp3/IabHelper$OnIabPurchaseFinishedListener;
    //   539: ifnull -89 -> 450
    //   542: new 380	com/melesta/payment/inapp3/IabResult
    //   545: dup
    //   546: iload 4
    //   548: ldc_w 438
    //   551: invokespecial 383	com/melesta/payment/inapp3/IabResult:<init>	(ILjava/lang/String;)V
    //   554: astore 9
    //   556: aload_0
    //   557: getfield 301	com/melesta/payment/inapp3/IabHelper:mPurchaseListener	Lcom/melesta/payment/inapp3/IabHelper$OnIabPurchaseFinishedListener;
    //   560: aload 9
    //   562: aconst_null
    //   563: invokeinterface 389 3 0
    //   568: goto -118 -> 450
    //   571: iload_2
    //   572: ifne +68 -> 640
    //   575: aload_0
    //   576: new 152	java/lang/StringBuilder
    //   579: dup
    //   580: invokespecial 153	java/lang/StringBuilder:<init>	()V
    //   583: ldc_w 440
    //   586: invokevirtual 160	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   589: iload 4
    //   591: invokestatic 252	com/melesta/payment/inapp3/IabHelper:getResponseDesc	(I)Ljava/lang/String;
    //   594: invokevirtual 160	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   597: invokevirtual 166	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   600: invokevirtual 136	com/melesta/payment/inapp3/IabHelper:logDebug	(Ljava/lang/String;)V
    //   603: new 380	com/melesta/payment/inapp3/IabResult
    //   606: dup
    //   607: sipush -1005
    //   610: ldc_w 442
    //   613: invokespecial 383	com/melesta/payment/inapp3/IabResult:<init>	(ILjava/lang/String;)V
    //   616: astore 8
    //   618: aload_0
    //   619: getfield 301	com/melesta/payment/inapp3/IabHelper:mPurchaseListener	Lcom/melesta/payment/inapp3/IabHelper$OnIabPurchaseFinishedListener;
    //   622: ifnull -172 -> 450
    //   625: aload_0
    //   626: getfield 301	com/melesta/payment/inapp3/IabHelper:mPurchaseListener	Lcom/melesta/payment/inapp3/IabHelper$OnIabPurchaseFinishedListener;
    //   629: aload 8
    //   631: aconst_null
    //   632: invokeinterface 389 3 0
    //   637: goto -187 -> 450
    //   640: aload_0
    //   641: new 152	java/lang/StringBuilder
    //   644: dup
    //   645: invokespecial 153	java/lang/StringBuilder:<init>	()V
    //   648: ldc_w 444
    //   651: invokevirtual 160	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   654: iload_2
    //   655: invokestatic 446	java/lang/Integer:toString	(I)Ljava/lang/String;
    //   658: invokevirtual 160	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   661: ldc_w 448
    //   664: invokevirtual 160	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   667: iload 4
    //   669: invokestatic 252	com/melesta/payment/inapp3/IabHelper:getResponseDesc	(I)Ljava/lang/String;
    //   672: invokevirtual 160	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   675: invokevirtual 166	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   678: invokevirtual 176	com/melesta/payment/inapp3/IabHelper:logError	(Ljava/lang/String;)V
    //   681: new 380	com/melesta/payment/inapp3/IabResult
    //   684: dup
    //   685: sipush -1006
    //   688: ldc_w 450
    //   691: invokespecial 383	com/melesta/payment/inapp3/IabResult:<init>	(ILjava/lang/String;)V
    //   694: astore 7
    //   696: aload_0
    //   697: getfield 301	com/melesta/payment/inapp3/IabHelper:mPurchaseListener	Lcom/melesta/payment/inapp3/IabHelper$OnIabPurchaseFinishedListener;
    //   700: ifnull -250 -> 450
    //   703: aload_0
    //   704: getfield 301	com/melesta/payment/inapp3/IabHelper:mPurchaseListener	Lcom/melesta/payment/inapp3/IabHelper$OnIabPurchaseFinishedListener;
    //   707: aload 7
    //   709: aconst_null
    //   710: invokeinterface 389 3 0
    //   715: goto -265 -> 450
    //   718: astore 12
    //   720: goto -266 -> 454
    //   723: iconst_1
    //   724: ireturn
    //
    // Exception table:
    //   from	to	target	type
    //   295	312	452	org/json/JSONException
    //   312	411	718	org/json/JSONException
    //   414	421	718	org/json/JSONException
  }

  public void launchPurchaseFlow(Activity paramActivity, String paramString, int paramInt, OnIabPurchaseFinishedListener paramOnIabPurchaseFinishedListener)
  {
    launchPurchaseFlow(paramActivity, paramString, paramInt, paramOnIabPurchaseFinishedListener, "");
  }

  public void launchPurchaseFlow(Activity paramActivity, String paramString1, int paramInt, OnIabPurchaseFinishedListener paramOnIabPurchaseFinishedListener, String paramString2)
  {
    launchPurchaseFlow(paramActivity, paramString1, "inapp", paramInt, paramOnIabPurchaseFinishedListener, paramString2);
  }

  public void launchPurchaseFlow(Activity paramActivity, String paramString1, String paramString2, int paramInt, OnIabPurchaseFinishedListener paramOnIabPurchaseFinishedListener, String paramString3)
  {
    checkSetupDone("launchPurchaseFlow");
    flagStartAsync("launchPurchaseFlow");
    if ((paramString2.equals("subs")) && (!this.mSubscriptionsSupported))
    {
      IabResult localIabResult4 = new IabResult(-1009, "Subscriptions are not available.");
      if (paramOnIabPurchaseFinishedListener != null)
        paramOnIabPurchaseFinishedListener.onIabPurchaseFinished(localIabResult4, null);
    }
    IabResult localIabResult1;
    do
      while (true)
      {
        return;
        try
        {
          logDebug("Constructing buy intent for " + paramString1 + ", item type: " + paramString2);
          localBundle = this.mService.getBuyIntent(3, this.mContext.getPackageName(), paramString1, paramString2, paramString3);
          int i = getResponseCodeFromBundle(localBundle);
          if (i != 0)
          {
            logError("Unable to buy item, Error response: " + getResponseDesc(i));
            IabResult localIabResult3 = new IabResult(i, "Unable to buy item");
            if (paramOnIabPurchaseFinishedListener == null)
              continue;
            paramOnIabPurchaseFinishedListener.onIabPurchaseFinished(localIabResult3, null);
          }
        }
        catch (IntentSender.SendIntentException localSendIntentException)
        {
          Bundle localBundle;
          logError("SendIntentException while launching purchase flow for sku " + paramString1);
          localSendIntentException.printStackTrace();
          IabResult localIabResult2 = new IabResult(-1004, "Failed to send intent.");
          if (paramOnIabPurchaseFinishedListener != null)
          {
            paramOnIabPurchaseFinishedListener.onIabPurchaseFinished(localIabResult2, null);
            return;
            PendingIntent localPendingIntent = (PendingIntent)localBundle.getParcelable("BUY_INTENT");
            logDebug("Launching buy intent for " + paramString1 + ". Request code: " + paramInt);
            this.mRequestCode = paramInt;
            this.mPurchaseListener = paramOnIabPurchaseFinishedListener;
            this.mPurchasingItemType = paramString2;
            paramActivity.startIntentSenderForResult(localPendingIntent.getIntentSender(), paramInt, new Intent(), Integer.valueOf(0).intValue(), Integer.valueOf(0).intValue(), Integer.valueOf(0).intValue());
            return;
          }
        }
        catch (RemoteException localRemoteException)
        {
          logError("RemoteException while launching purchase flow for sku " + paramString1);
          localRemoteException.printStackTrace();
          localIabResult1 = new IabResult(-1001, "Remote exception while starting purchase flow");
        }
      }
    while (paramOnIabPurchaseFinishedListener == null);
    paramOnIabPurchaseFinishedListener.onIabPurchaseFinished(localIabResult1, null);
  }

  public void launchSubscriptionPurchaseFlow(Activity paramActivity, String paramString, int paramInt, OnIabPurchaseFinishedListener paramOnIabPurchaseFinishedListener)
  {
    launchSubscriptionPurchaseFlow(paramActivity, paramString, paramInt, paramOnIabPurchaseFinishedListener, "");
  }

  public void launchSubscriptionPurchaseFlow(Activity paramActivity, String paramString1, int paramInt, OnIabPurchaseFinishedListener paramOnIabPurchaseFinishedListener, String paramString2)
  {
    launchPurchaseFlow(paramActivity, paramString1, "subs", paramInt, paramOnIabPurchaseFinishedListener, paramString2);
  }

  void logDebug(String paramString)
  {
    if (this.mDebugLog)
      Log.d(this.mDebugTag, paramString);
  }

  void logError(String paramString)
  {
    Log.e(this.mDebugTag, "In-app billing error: " + paramString);
  }

  void logWarn(String paramString)
  {
    Log.w(this.mDebugTag, "In-app billing warning: " + paramString);
  }

  public Inventory queryInventory(boolean paramBoolean, List<String> paramList)
    throws IabException
  {
    return queryInventory(paramBoolean, paramList, null);
  }

  public Inventory queryInventory(boolean paramBoolean, List<String> paramList1, List<String> paramList2)
    throws IabException
  {
    checkSetupDone("queryInventory");
    Inventory localInventory;
    try
    {
      localInventory = new Inventory();
      int i = queryPurchases(localInventory, "inapp");
      if (i != 0)
        throw new IabException(i, "Error refreshing inventory (querying owned items).");
    }
    catch (RemoteException localRemoteException)
    {
      throw new IabException(-1001, "Remote exception while refreshing inventory.", localRemoteException);
      if (paramBoolean)
      {
        int m = querySkuDetails("inapp", localInventory, paramList1);
        if (m != 0)
          throw new IabException(m, "Error refreshing inventory (querying prices of items).");
      }
    }
    catch (JSONException localJSONException)
    {
      throw new IabException(-1002, "Error parsing JSON response while refreshing inventory.", localJSONException);
    }
    if (this.mSubscriptionsSupported)
    {
      int j = queryPurchases(localInventory, "subs");
      if (j != 0)
        throw new IabException(j, "Error refreshing inventory (querying owned subscriptions).");
      if (paramBoolean)
      {
        int k = querySkuDetails("subs", localInventory, paramList1);
        if (k != 0)
          throw new IabException(k, "Error refreshing inventory (querying prices of subscriptions).");
      }
    }
    return localInventory;
  }

  public void queryInventoryAsync(QueryInventoryFinishedListener paramQueryInventoryFinishedListener)
  {
    queryInventoryAsync(true, null, paramQueryInventoryFinishedListener);
  }

  public void queryInventoryAsync(boolean paramBoolean, QueryInventoryFinishedListener paramQueryInventoryFinishedListener)
  {
    queryInventoryAsync(paramBoolean, null, paramQueryInventoryFinishedListener);
  }

  public void queryInventoryAsync(final boolean paramBoolean, final List<String> paramList, final QueryInventoryFinishedListener paramQueryInventoryFinishedListener)
  {
    final Handler localHandler = new Handler();
    checkSetupDone("queryInventory");
    flagStartAsync("refresh inventory");
    new Thread(new Runnable()
    {
      public void run()
      {
        IabResult localIabResult1 = new IabResult(0, "Inventory refresh successful.");
        try
        {
          Inventory localInventory3 = IabHelper.this.queryInventory(paramBoolean, paramList);
          localInventory1 = localInventory3;
          IabHelper.this.flagEndAsync();
          final IabResult localIabResult2 = localIabResult1;
          final Inventory localInventory2 = localInventory1;
          localHandler.post(new Runnable()
          {
            public void run()
            {
              IabHelper.2.this.val$listener.onQueryInventoryFinished(localIabResult2, localInventory2);
            }
          });
          return;
        }
        catch (IabException localIabException)
        {
          while (true)
          {
            localIabResult1 = localIabException.getResult();
            Inventory localInventory1 = null;
          }
        }
      }
    }).start();
  }

  int queryPurchases(Inventory paramInventory, String paramString)
    throws JSONException, RemoteException
  {
    logDebug("Querying owned items, item type: " + paramString);
    logDebug("Package name: " + this.mContext.getPackageName());
    int i = 0;
    String str1 = null;
    do
    {
      logDebug("Calling getPurchases with continuation token: " + str1);
      Bundle localBundle = this.mService.getPurchases(3, this.mContext.getPackageName(), paramString, str1);
      int j = getResponseCodeFromBundle(localBundle);
      logDebug("Owned items response: " + String.valueOf(j));
      if (j != 0)
      {
        logDebug("getPurchases() failed: " + getResponseDesc(j));
        return j;
      }
      if ((!localBundle.containsKey("INAPP_PURCHASE_ITEM_LIST")) || (!localBundle.containsKey("INAPP_PURCHASE_DATA_LIST")) || (!localBundle.containsKey("INAPP_DATA_SIGNATURE_LIST")))
      {
        logError("Bundle returned from getPurchases() doesn't contain required fields.");
        return -1002;
      }
      ArrayList localArrayList1 = localBundle.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
      ArrayList localArrayList2 = localBundle.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
      ArrayList localArrayList3 = localBundle.getStringArrayList("INAPP_DATA_SIGNATURE_LIST");
      int k = 0;
      if (k < localArrayList2.size())
      {
        String str2 = (String)localArrayList2.get(k);
        String str3 = (String)localArrayList3.get(k);
        String str4 = (String)localArrayList1.get(k);
        if (Security.verifyPurchase(this.mSignatureBase64, str2, str3))
        {
          logDebug("Sku is owned: " + str4);
          Purchase localPurchase = new Purchase(paramString, str2, str3);
          if (TextUtils.isEmpty(localPurchase.getToken()))
          {
            logWarn("BUG: empty/null token!");
            logDebug("Purchase data: " + str2);
          }
          paramInventory.addPurchase(localPurchase);
        }
        while (true)
        {
          k++;
          break;
          logWarn("Purchase signature verification **FAILED**. Not adding item.");
          logDebug("   Purchase data: " + str2);
          logDebug("   Signature: " + str3);
          i = 1;
        }
      }
      str1 = localBundle.getString("INAPP_CONTINUATION_TOKEN");
      logDebug("Continuation token: " + str1);
    }
    while (!TextUtils.isEmpty(str1));
    if (i != 0);
    for (int m = -1003; ; m = 0)
      return m;
  }

  int querySkuDetails(String paramString, Inventory paramInventory, List<String> paramList)
    throws RemoteException, JSONException
  {
    logDebug("Querying SKU details.");
    ArrayList localArrayList = new ArrayList();
    localArrayList.addAll(paramInventory.getAllOwnedSkus(paramString));
    if (paramList != null)
      localArrayList.addAll(paramList);
    if (localArrayList.size() == 0)
      logDebug("queryPrices: nothing to do because there are no SKUs.");
    while (true)
    {
      return 0;
      Bundle localBundle1 = new Bundle();
      localBundle1.putStringArrayList("ITEM_ID_LIST", localArrayList);
      Bundle localBundle2 = this.mService.getSkuDetails(3, this.mContext.getPackageName(), paramString, localBundle1);
      if (!localBundle2.containsKey("DETAILS_LIST"))
      {
        int i = getResponseCodeFromBundle(localBundle2);
        if (i != 0)
        {
          logDebug("getSkuDetails() failed: " + getResponseDesc(i));
          return i;
        }
        logError("getSkuDetails() returned a bundle with neither an error nor a detail list.");
        return -1002;
      }
      Iterator localIterator = localBundle2.getStringArrayList("DETAILS_LIST").iterator();
      while (localIterator.hasNext())
      {
        SkuDetails localSkuDetails = new SkuDetails(paramString, (String)localIterator.next());
        logDebug("Got sku details: " + localSkuDetails);
        paramInventory.addSkuDetails(localSkuDetails);
      }
    }
  }

  public void startSetup(final OnIabSetupFinishedListener paramOnIabSetupFinishedListener)
  {
    if (this.mSetupDone)
      throw new IllegalStateException("IAB helper is already set up.");
    logDebug("Starting in-app billing setup.");
    this.mServiceConn = new ServiceConnection()
    {
      public void onServiceConnected(ComponentName paramAnonymousComponentName, IBinder paramAnonymousIBinder)
      {
        IabHelper.this.logDebug("Billing service connected.");
        IabHelper.this.mService = IInAppBillingService.Stub.asInterface(paramAnonymousIBinder);
        String str = IabHelper.this.mContext.getPackageName();
        try
        {
          IabHelper.this.logDebug("Checking for in-app billing 3 support.");
          int i = IabHelper.this.mService.isBillingSupported(3, str, "inapp");
          if (i != 0)
          {
            if (paramOnIabSetupFinishedListener != null)
              paramOnIabSetupFinishedListener.onIabSetupFinished(new IabResult(i, "Error checking for billing v3 support."));
            IabHelper.this.mSubscriptionsSupported = false;
            return;
          }
          IabHelper.this.logDebug("In-app billing version 3 supported for " + str);
          int j = IabHelper.this.mService.isBillingSupported(3, str, "subs");
          if (j == 0)
          {
            IabHelper.this.logDebug("Subscriptions AVAILABLE.");
            IabHelper.this.mSubscriptionsSupported = true;
          }
          while (true)
          {
            IabHelper.this.mSetupDone = true;
            if (paramOnIabSetupFinishedListener == null)
              break;
            paramOnIabSetupFinishedListener.onIabSetupFinished(new IabResult(0, "Setup successful."));
            return;
            IabHelper.this.logDebug("Subscriptions NOT AVAILABLE. Response: " + j);
          }
        }
        catch (RemoteException localRemoteException)
        {
          if (paramOnIabSetupFinishedListener != null)
            paramOnIabSetupFinishedListener.onIabSetupFinished(new IabResult(-1001, "RemoteException while setting up in-app billing."));
          localRemoteException.printStackTrace();
        }
      }

      public void onServiceDisconnected(ComponentName paramAnonymousComponentName)
      {
        IabHelper.this.logDebug("Billing service disconnected.");
        IabHelper.this.mService = null;
      }
    };
    Intent localIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    if (!this.mContext.getPackageManager().queryIntentServices(localIntent, 0).isEmpty())
      this.mContext.bindService(localIntent, this.mServiceConn, 1);
    while (paramOnIabSetupFinishedListener == null)
      return;
    paramOnIabSetupFinishedListener.onIabSetupFinished(new IabResult(3, "Billing service unavailable on device."));
  }

  public boolean subscriptionsSupported()
  {
    return this.mSubscriptionsSupported;
  }

  public static abstract interface OnConsumeFinishedListener
  {
    public abstract void onConsumeFinished(Purchase paramPurchase, IabResult paramIabResult);
  }

  public static abstract interface OnConsumeMultiFinishedListener
  {
    public abstract void onConsumeMultiFinished(List<Purchase> paramList, List<IabResult> paramList1);
  }

  public static abstract interface OnIabPurchaseFinishedListener
  {
    public abstract void onIabPurchaseFinished(IabResult paramIabResult, Purchase paramPurchase);
  }

  public static abstract interface OnIabSetupFinishedListener
  {
    public abstract void onIabSetupFinished(IabResult paramIabResult);
  }

  public static abstract interface QueryInventoryFinishedListener
  {
    public abstract void onQueryInventoryFinished(IabResult paramIabResult, Inventory paramInventory);
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.melesta.payment.inapp3.IabHelper
 * JD-Core Version:    0.6.2
 */